package com.wnhz.work.yz.activity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.google.gson.Gson;
import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.MyApplication;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.ReserveMessageBean;
import com.wnhz.work.yz.utils.Url;
import com.wnhz.work.yz.utils.xutils3.MyCallBack;
import com.wnhz.work.yz.utils.xutils3.XUtil;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * ---预约信息
 */
public class ReserveMessageActivity extends BaseActivity implements View.OnClickListener {
    private TextView title;
    private TextView tv_name, tv_name_message, tv_phone, tv_address, tv_authentication,
            tv_number, tv_start_time, tv_goods, tv_area, tv_reserve_time, tv_call_time;

    private void initId() {
        tv_name = (TextView) findViewById(R.id.tv_name);
        tv_name_message = (TextView) findViewById(R.id.tv_name_message);
        tv_authentication = (TextView) findViewById(R.id.tv_authentication);
        tv_phone = (TextView) findViewById(R.id.tv_phone);
        tv_address = (TextView) findViewById(R.id.tv_address);
        tv_number = (TextView) findViewById(R.id.tv_number);
        tv_start_time = (TextView) findViewById(R.id.tv_start_time);
        tv_goods = (TextView) findViewById(R.id.tv_goods);
        tv_area = (TextView) findViewById(R.id.tv_area);
        tv_reserve_time = (TextView) findViewById(R.id.tv_reserve_time);
        tv_call_time = (TextView) findViewById(R.id.tv_call_time);
    }

    private void setData() {
        tv_name.setText(bean.getName());
        tv_name_message.setText(bean.getName());
        tv_authentication.setText(isex);
        tv_phone.setText(bean.getMobile());
        tv_address.setText(bean.getPlace());
        tv_number.setText(bean.getAppoint_no());
        tv_call_time.setText(bean.getAppoint_start_time() + "-" + bean.getAppoint_end_time());
        tv_reserve_time.setText(bean.getTime());
        tv_goods.setText(bean.getAppoint_goods());
        tv_area.setText(bean.getItem_area());
        tv_start_time.setText(bean.getTime());


    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reserve_message);

        initData();
        initView();
        upLoad();
    }

    ReserveMessageBean bean;

    private void upLoad() {
        //UCENTER_APPOINTDETAIL
        Map<String, Object> map = new HashMap<>();
        map.put("token", MyApplication.getInstance().getUserBean().getToken());
        map.put("appo_id", appo_id);
        //Log.i(TAG, MyApplication.getInstance().getUserBean().getToken());
        XUtil.Post(Url.UCENTER_APPOINTDETAIL, map, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                try {
                    Log.e("ReserveMessageActivity", "onSuccess: " + result);
                    Gson gson = new Gson();
                    JSONObject jsonObject = new JSONObject(result);
                    bean = gson.fromJson(jsonObject.optString("info"), ReserveMessageBean.class);
                } catch (Exception e) {
                    e.printStackTrace();
                }

            }

            @Override
            public void onFinished() {
                super.onFinished();
                hideProgress();
                setData();
            }


            @Override
            public void onError(Throwable ex, boolean isOnCallback) {
                super.onError(ex, isOnCallback);
            }
        });
    }


    private String appo_id;
    private String isex;

    private void initData() {
        appo_id = getIntent().getStringExtra("appo_id");
        isex = getIntent().getStringExtra("isex");
    }

    private void initView() {
        title = (TextView) findViewById(R.id.view_main_middle_title);
        title.setText("预约信息");
        findViewById(R.id.btn_main_left).setOnClickListener(this);
        findViewById(R.id.tv_change).setOnClickListener(this);

        initId();
    }


    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            case R.id.btn_main_left:
                finish();
                break;

            //转成备案
            case R.id.tv_change:
                MyToast("转成备案");
                break;

            default:
                break;
        }
    }
}
